package com.dotflat.survey.controller;

import com.dotflat.docs.domain.Document;
import com.dotflat.docs.po.DocumentPO;
import com.dotflat.docs.service.DocumentService;
import com.dotflat.rest.controller.RestfulBaseController;
import com.dotflat.survey.domain.SurveySheet;
import com.dotflat.survey.dto.SurveyAnswerDTO;
import com.dotflat.survey.dto.SurveySheetDTO;
import com.dotflat.survey.po.SurveySheetPO;
import com.dotflat.survey.service.SurveySheetItemService;
import com.dotflat.survey.service.SurveySheetService;
import com.starinside.wp.domain.Children;
import com.starinside.wp.foundation.exception.BusinessException;
import com.starinside.wp.foundation.model.ErrorCode;
import com.starinside.wp.foundation.model.StatusResponse;
import com.starinside.wp.foundation.query.base.PagerQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.lang.reflect.Field;

import static com.starinside.wp.foundation.constant.RequestConstant.TICKET;


@RestController
@RequestMapping("/v2/survey/sheet")
@Slf4j
@Api(tags = "问卷 - 模板")
public class SurveySheetController extends RestfulBaseController<SurveySheet, SurveySheetService, SurveySheetPO> {

    @Autowired
    public void setBaseService(SurveySheetService service){
        super.setBaseService(service);
    }

    @Override
    @ApiOperation(value = "获取一个对象", response = SurveySheet.class)
    @GetMapping()
    public StatusResponse get(@RequestHeader(TICKET) String ticket, HttpServletRequest req, String id){
        return super.get(ticket, req, id);
    }

    @ApiOperation(value = "获取列表", response = SurveySheetDTO.class)
    @GetMapping("/list")
    public StatusResponse getList(@RequestHeader(TICKET) String ticket, HttpServletRequest req, SurveySheetPO param, PagerQuery pagerQuery){
        StatusResponse ret = super.getList(ticket, req, param, pagerQuery);

        Page<SurveySheet> page = (Page<SurveySheet>) ret.getData();

        Page<SurveySheetDTO> newPage = page.map(o-> SurveySheetDTO.of(o));

        return StatusResponse.success(newPage);
    }
}
